/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import java.awt.Color;
import java.awt.Image;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import model.PionType;
import model.Stuk;

/**
 *
 * @author Stijn Delbeke
 */
public class Vak extends JLabel {

    private final int ICONGROOTTE = 50;
    private PionType type;
    private boolean bevatPion;
    private boolean isLand;
    private Stuk pion;
    private int xPos;
    private int yPos;

    public Vak() {
        type = new PionType();
        bevatPion = false;
        isLand = true;

        setBorder(BorderFactory.createLineBorder(Color.BLACK));

        setOpaque(true);
        setBackground(Color.LIGHT_GRAY);

    }

    public void createIcon(PionType p, String kleur) {
        String path = "../icons/" + p.getNaam() + "_" + kleur + ".jpg";
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            try {
                Image img = ImageIO.read(imgURL);
                img = img.getScaledInstance(ICONGROOTTE, ICONGROOTTE, Image.SCALE_AREA_AVERAGING);
                this.setIcon(new ImageIcon(img));
            }
            catch (IOException io) {
                io.printStackTrace();
            }
        }

    }

    public void createIcon(String path) {
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            try {
                Image img = ImageIO.read(imgURL);
                img = img.getScaledInstance(ICONGROOTTE, ICONGROOTTE, Image.SCALE_AREA_AVERAGING);
                this.setIcon(new ImageIcon(img));
            }
            catch (IOException io) {
                io.printStackTrace();
            }
        }
    }

    public int getxPos() {
        return xPos;
    }

    public int getyPos() {
        return yPos;
    }

    public void setxPos(int xPos) {
        this.xPos = xPos;
    }

    public void setyPos(int yPos) {
        this.yPos = yPos;
    }

    public boolean bevatPion() {
        return bevatPion;
    }

    public boolean isLand() {
        return isLand;
    }

    public Color getKleur() {
        return super.getBackground();
    }

    public Stuk getPion() {
        return pion;
    }

    public void setLand(boolean isGeldig) {
        this.isLand = isGeldig;
    }

    public void setPion(Stuk stuk) {
        this.pion = stuk;
        this.bevatPion = true;
    }

    public void removePion() {
        this.pion = null;
        this.bevatPion = false;
        this.setIcon(null);


    }
}
